//
//  SLCoreCertificationTableViewCell.m
//  SulitLoan
//
//  Created by 虞嘉伟 on 2025/2/24.
//

#import "SLCoreCertificationTableViewCell.h"
#import <YYKit.h>
#import <Masonry.h>

@interface SLCoreCertificationTableViewCell ()
@property (nonatomic, strong) UIView *bgView;
@end

@implementation SLCoreCertificationTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        SLCertificationProductItemComponent *productCard = [SLCertificationProductItemComponent new];
        _productCard = productCard;
        [self.contentView addSubview:productCard];
        [productCard mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView).inset(20);
            make.height.mas_equalTo(142);
            make.top.mas_equalTo(20);
        }];
        
        _bgView = [UIView new];
        [self.contentView addSubview:_bgView];
        [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView);
            make.top.equalTo(productCard.mas_bottom).offset(29);
            make.bottom.equalTo(self.contentView);
        }];
        
        SLStartAuthenticationComponent *start = [SLStartAuthenticationComponent new];
        _start = start;
        [self.contentView addSubview:start];
        [start mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView).inset(0);
            make.height.mas_equalTo(122);
            make.top.mas_equalTo(productCard.mas_bottom);
        }];
        
        SLCertificationListComponent *list = [SLCertificationListComponent new];
        _list = list;
        [self.contentView addSubview:list];
        [list mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView).inset(0);
            make.top.mas_equalTo(start.mas_bottom);
        }];
        
        // 底部协议
        UILabel *privacyPolicyLabel = [UILabel new];
        privacyPolicyLabel.numberOfLines = 0;
        privacyPolicyLabel.userInteractionEnabled = YES;
        privacyPolicyLabel.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:privacyPolicyLabel];
        privacyPolicyLabel.text = @"How Exactly Do We Respect And Safeguard Your Privacy? It's All Specified In The Privacy Policy.";
        NSString *text = privacyPolicyLabel.text;
        NSRange range2 = [text rangeOfString:@"Privacy Policy"];
        // 创建富文本
        NSMutableAttributedString *attrText = [[NSMutableAttributedString alloc] initWithString:text];
        [attrText setColor:UIColorHex(#999999) range:NSMakeRange(0, text.length)];
        [attrText setFont:aspectDefaultFont(12) range:NSMakeRange(0, text.length)];
        [attrText setColor:UIColorHex(#333333) range:range2];
        [attrText setFont:aspectDefaultFont(12) range:range2];
        [attrText setTextHighlightRange:range2 // 设置高亮范围
                                  color:UIColorHex(#333333) //UIColorHex(#1B1B1B)
                        backgroundColor:[UIColor clearColor]
                              tapAction:^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect) {
            NSLog(@"点击了高亮文本");
            // 在这里处理点击事件
            [SLRoutePush route:Configuration.PrivacyPolicyDomain parameter:nil];
        }];
        privacyPolicyLabel.attributedText = attrText;
        [privacyPolicyLabel sizeToFit];
        [privacyPolicyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.equalTo(self.contentView).inset(34);
            make.top.mas_equalTo(list.mas_bottom).offset(49);
            make.bottom.equalTo(self.bgView);
        }];
        [privacyPolicyLabel jk_addTapActionWithBlock:^(UIGestureRecognizer *gestureRecoginzer) {
            [SLRoutePush route:Configuration.PrivacyPolicyDomain parameter:nil];
        }];
    }
    return self;
}

@end
